<?php

use App\Http\Controllers\Admin\PermissionController;
use App\Http\Controllers\Admin\RoleController;
use App\Http\Controllers\Admin\SettingsController;
use App\Http\Controllers\Admin\UserController;
use App\Http\Controllers\Auth\AuthController;
use App\Http\Controllers\HealthController;
use App\Http\Controllers\TestController;
use App\Http\Middleware\Management\ArticleController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "api" middleware group. Make something great!
|
*/

Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
    return $request->user();
});
// 测试路由
//Route::get("/test/getall",[TestController::class,"getAll"]);
//Route::get("/test/get",[TestController::class,"get"]);
//Route::post("/test/post",[TestController::class,"post"]);
//Route::put("/test/put",[TestController::class,"put"]);
//Route::delete("/test/delete",[TestController::class,"delete"]);

Route::prefix("test")
    ->controller(TestController::class)
    ->group(function ($router) {
        $router->get("/getall", "getAll")->middleware("jwt_auth");
        $router->get("/get", "get");
        $router->post("/post", "post");
        $router->put("/put", "put");
        $router->delete("/delete", "delete");
        $router->post("/unauthorized", "unauthorized");
    });

//路由鉴权
Route::prefix("auth")
    ->controller(AuthController::class)
    ->middleware("jwt_auth")
    ->group(function ($router) {
        // 注册
        $router->post("/register", "register")->withoutMiddleware("jwt_auth");
        // 登录
        $router->post("/login", "login")->withoutMiddleware("jwt_auth");
        // 退出登录
        $router->post("/logout", "logout");
        // 修改用户信息
        $router->put("/edit", "edit");
        // 修改用户密码
        $router->put("/changePassword", "changePassword");
        // 用户头像
        $router->post("/avatar", "avatar");
        // 获取用户信息
        $router->get("/detail", "detail");
        // 获取用户头像
        $router->get("/getAvatar", "getAvatar");
        // 获取用户权限
        $router->get("/getPermissions", "getPermissions");
        // 获取用户权限数量
        $router->get("/getPermissionsCount", "getPermissionsCount");
        // 获取用户菜单
        $router->get("/getMenus", "getMenus");
        // 获取系统设置
        $router->get("/settings/get", [SettingsController::class, "get"])->withoutMiddleware("jwt_auth");
        // 更新系统设置
        $router->post("/settings/update", [SettingsController::class, "update"]);
        // 更新仪表盘标题
        $router->post('/settings/dashboard_title_update', [SettingsController::class, 'updateDashboardTitle']);
        // 获取仪表盘标题
$router->get('/settings/dashboard_title_get', [SettingsController::class, 'getDashboardTitle']);
    });
//后台管理
Route::prefix("admin")->middleware(["jwt_auth", "permission_auth"])->group(function ($router) {
    //角色管理
    $router->prefix("role")->controller(RoleController::class)->group(function ($router1) {
        $router1->get("/list", "list");
        $router1->post("/create", "create");
        $router1->put("/edit", "edit");
        $router1->delete("/delete", "delete");
    });
    //用户管理
    $router->prefix("user")->controller(UserController::class)->group(function ($router1) {
        $router1->get("/list", "list");
        $router1->post("/create", "create");
        $router1->put("/edit", "edit");
        $router1->delete("/delete", "delete")->withoutMiddleware(["jwt_auth", "permission_auth"]);
        $router1->patch("/setRole", "setRole");
        $router1->post("/uploadAvatar", "uploadAvatar")->withoutMiddleware(["jwt_auth", "permission_auth"]);
        $router1->get("/getRoles", "getRoles")->withoutMiddleware(["jwt_auth", "permission_auth"]);
    });
    //权限管理
    $router->prefix("permission")->controller(PermissionController::class)->group(function ($router1) {
        $router1->get("/get", "get");
        $router1->post("/save", "save");
    });
});
//文章管理
Route::prefix("article")
    ->controller(ArticleController::class)
    ->middleware(["jwt_auth", "permission_auth"])
    ->group(function ($router) {
        $router->get("/list", "list");
        $router->post("/create", "create");
        $router->put("/edit", "edit");
        $router->delete("/delete", "delete");
        $router->get("/file", "file");
        $router->post("/upload", "upload");
    });
Route::prefix("health")
    ->controller(HealthController::class)
    ->group(function ($router) {
        // 系统健康检查
        $router->get('/status', [HealthController::class, 'checkStatus']);
        // 数据库健康检查
        $router->get('/database', [HealthController::class, 'checkDatabase']);
    });
Route::prefix("settings")
    ->controller(SettingsController::class)
    ->group(function ($router) {
        // 获取nginx检查状态
        $router->get('/ngx_check_get', [SettingsController::class, 'getNginxCheck']);
    });


